package com.ucomm.talent.activity.detail;

import com.ucomm.talent.AppConstants;
import com.ucomm.talent.AppException;
import com.ucomm.talent.R;
import com.ucomm.talent.activity.IHeaderBarClickListener;
import com.ucomm.talent.common.DebugUtil;
import com.ucomm.talent.manager.DetailSearchManager;
import com.ucomm.talent.model.JobFairDetailsInfo;
import com.ucomm.talent.model.JobFairInfo;
import com.ucomm.talent.widget.CustomProgressDialog;
import com.ucomm.talent.widget.MainHeaderBar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewStub;
import android.widget.TextView;

public class JobFairDetailsActivity extends Activity implements IHeaderBarClickListener{
	
	private int id = 0; 
	private MainHeaderBar mainHeaderBar;
	private CustomProgressDialog customProgressDialog;
	private DetailSearchManager detailSearchManager;
	private TextView fair_title;
	private TextView organizers;
	private TextView fair_address;
	private JobFairInfo info;
	private ViewStub fair_details_vs1;
	private TextView fair_description;
	private TextView traffic;
	
	Handler mHandler = new Handler(){
        @Override
    public void handleMessage(Message msg) {
        int what = msg.what;
        DebugUtil.Log(JobFairDetailsActivity.this,"---------- " + customProgressDialog.toString());
        switch (what){
            case AppConstants.MsgStatus.MSG_ERROR:
                if (customProgressDialog != null && customProgressDialog.isShowing())
                    customProgressDialog.dismiss();
                ((AppException)msg.obj).makeToast(JobFairDetailsActivity.this);
                break;
            case AppConstants.MsgStatus.MSG_SUCCUSS:
                if (customProgressDialog != null && customProgressDialog.isShowing())
                    customProgressDialog.dismiss();
                //获取数据
                JobFairDetailsInfo details = (JobFairDetailsInfo) msg.obj;
                traffic.setText(details.getTraffic());
                fair_description.setText(details.getFairDescription());
                break;
            case AppConstants.MsgStatus.MSG_LOADING:
                if (customProgressDialog != null && !customProgressDialog.isShowing())
                    customProgressDialog.show();
                break;
            default:
                break;
        }
        super.handleMessage(msg);
    }
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.job_fair_details_activity);
		//获取数据
		Intent i = getIntent();
		info = (JobFairInfo) i.getSerializableExtra("info");
		//招聘现场id根据此id获取详细信息
		id = info.getJobFairId();
		initView();
        detailSearchManager = new DetailSearchManager(this, mHandler);
        final String url = AppConstants.JOB_FAIR_DETAILS+id;
        detailSearchManager.searchDetailDataFromNetwork(url);
	}
	private void initView(){
		mainHeaderBar = (MainHeaderBar) findViewById(R.id.main_header_bar);
		mainHeaderBar.setBarClickListener(this);
		customProgressDialog = new CustomProgressDialog(this);
		fair_title = (TextView) findViewById(R.id.fair_title);
		organizers = (TextView) findViewById(R.id.organizers);
		fair_address = (TextView) findViewById(R.id.fair_address);
		traffic = (TextView) findViewById(R.id.traffic);
		fair_details_vs1 = (ViewStub) findViewById(R.id.fair_details_vs1);
		fair_title.setText(info.getTitle());
		organizers.setText(info.getOrganizers());
		fair_address.setText(info.getAddress());
		fair_details_vs1.inflate();
		fair_description = (TextView) findViewById(R.id.fair_description);
	}

	@Override
	public void onBackButtOnClick(View view) {
		finish();
		
	}

	@Override
	public void onExitButtonOnClick(View view) {
		// TODO Auto-generated method stub
		
	}
}

